<?php
class MsepCore_Api_Core extends Core_Api_Abstract {
	
	public function jsColor() {
		$this->getView ()->headScript ()->appendFile ( 'application/modules/MsepCore/externals/scripts/jscolor/jscolor.js', 'text/javascript' );
	}
	
	public function tol() {
		$this->getView ()->headScript ()->appendFile ( 'application/modules/MsepCore/externals/scripts/TextOverlap/mootools.tol.js', 'text/javascript' );
	}
	
	public function getView() {
		return Engine_Api::_ ()->getApplication ()->getBootstrap ()->getContainer ()->get ( 'Zend_View' );
	}
	
	public function addStyle($css) {
		$this->getView ()->headStyle ()->appendStyle ( $css );
	}
	
	public function addStyleFile($file) {
		$this->getView ()->headLink ()->appendStylesheet ( $file );
	}
	
	public function addScript($script) {
		$this->getView ()->headScript ()->appendScript ( $script );
	}
	
	public function cleanData($values, $prefix) {
		foreach ( $values as $key => $value ) {
			if (substr ( $key, 0, strlen ( $prefix ) ) != $prefix) {
				unset ( $values [$key] );
			}
		}
		
		return $values;
	}
	
	public function matchByColumn($table, $values) {
		$return = array ();
		
		$cols = $table->info ( Zend_Db_Table_Abstract::COLS );
		
		foreach ( $cols as $key ) {
			if (! empty ( $values [$key] ))
				$return [$key] = $values [$key];
		}
		
		return $return;
	}
	
	public function array_search_recursive($needle, $haystack, $strict = false, $path = array()) {
		if (! is_array ( $haystack ))
			return false;
		
		foreach ( $haystack as $key => $val ) {
			if (is_array ( $val ) && $subPath = $this->array_search_recursive ( $needle, $val, $strict, $path )) {
				$path = array_merge ( $path, array ($key ), $subPath );
				
				return $path;
			} elseif ((! $strict && $val == $needle) || ($strict && $val === $needle)) {
				$path [] = $key;
				
				return $path;
			}
		}
		
		return false;
	}

}
